package com.ozy.kxreader.mvp.ui.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseSectionQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chad.library.adapter.base.entity.SectionEntity
import com.ozy.kxreader.R
import com.ozy.kxreader.mvp.model.entity.Category
import kotlinx.android.synthetic.main.item_category_content.view.*

/**
 * Created by 欧源 on 2018/2/1.
 */

class CategoryAdapter :
        BaseSectionQuickAdapter<SectionEntity<Category>, BaseViewHolder>(R.layout.item_category_content, R.layout.item_category_title, ArrayList()) {

    override fun convert(helper: BaseViewHolder?, item: SectionEntity<Category>?) {
        val category = item?.t;
        helper!!.itemView.tv_title.text = category?.name
        helper?.itemView.tv_count.text = category?.bookCount + "本"
    }

    override fun convertHead(helper: BaseViewHolder?, item: SectionEntity<Category>?) {
        (helper!!.itemView as TextView).text = item?.header
    }

    fun getHeaderItem(position: Int): SectionEntity<*>? {
        val data = data
        for (i in position downTo 0) {
            val entity = data[i]
            if (entity.isHeader) {
                return entity
            }
        }
        return null
    }
}
